package Server;
import java.io.IOException;

import java.net.InetSocketAddress;
import java.nio.charset.Charset;

import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import Server.Date.*;
import Server.Timp.*;

public class RealTimeServer
{
	private static final int PORT = 9123;
	public static void main( String[] args ) throws IOException
	{
		
		ReadWriteTextFile rd=new ReadWriteTextFile();
		rd.start();
		System.out.println("asdasd");
		IoAcceptor acceptor = new NioSocketAcceptor();

		acceptor.getFilterChain().addLast( "logger", new LoggingFilter() );
		acceptor.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new TextLineCodecFactory( Charset.forName( "UTF-8" ))));

		acceptor.setHandler( new ServerHandler(rd) );
		acceptor.getSessionConfig().setReadBufferSize( 2048 );
		acceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, 10 );
		acceptor.bind( new InetSocketAddress(PORT) );
	}
}
